package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.sumpu.app.guoguojie.dao.AccountDrawApplyDao;
import cn.sumpu.app.guoguojie.domain.AccountDrawApply;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class AccountDrawApplyDaoImpl extends SqlSessionDaoSupport implements AccountDrawApplyDao {
    private final static Logger logger = LoggerFactory.getLogger(AccountDrawApplyDaoImpl.class);

    //添加 会员提现申请
    @Override
    public void addAccountDrawApply(AccountDrawApply apply) throws AppBusinessException {
        try {
            getSqlSession()
                    .insert("cn.sumpu.app.guoguojie.persistence.AccountDrawApplyMapper.addAccountDrawApply",
                        apply);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("addAccountDrawApply database failure.", e);
            }
            throw new AppBusinessException("addAccountDrawApply database failure.", e);
        }
    }
    //根据ID查询 会员提现申请 信息
    @Override
    public void updateAccountDrawApply(AccountDrawApply apply) throws AppBusinessException {
        try {
            getSqlSession()
                    .update("cn.sumpu.app.guoguojie.persistence.AccountDrawApplyMapper.updateAccountDrawApply",
                        apply);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateAccountDrawApply database failure.", e);
            }
            throw new AppBusinessException("updateAccountDrawApply database failure.", e);
        }
    }

    //根据ID查询 会员提现申请 信息
    @Override
    public AccountDrawApply getAdaById(String id) throws AppBusinessException {
        try {
            return (AccountDrawApply) getSqlSession()
                    .selectOne("cn.sumpu.app.guoguojie.persistence.AccountDrawApplyMapper.getAdaById",
                        id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getAdaById database failure.", e);
            }
            throw new AppBusinessException("getAdaById database failure.", e);
        }
    }

    //查询 会员提现申请 列表
    @SuppressWarnings("unchecked")
    @Override
    public List<AccountDrawApply> getAdasByCondition(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<AccountDrawApply>) getSqlSession()
                    .selectList("cn.sumpu.app.guoguojie.persistence.AccountDrawApplyMapper.getAdasByCondition",
                        map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getAdasByCondition database failure.", e);
            }
            throw new AppBusinessException("getAdasByCondition database failure.", e);
        }
    }
    //查询 会员提现申请 总数
    @Override
    public Integer getAdaCountByCondition(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession()
                    .selectOne("cn.sumpu.app.guoguojie.persistence.AccountDrawApplyMapper.getAdaCountByCondition",
                        map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getAdaCountByCondition database failure.", e);
            }
            throw new AppBusinessException("getAdaCountByCondition database failure.", e);
        }
    }

}
